using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using ShopForWeb.Dto.ViewModels;
using ShopForWeb.UI.Extensions;

namespace ShopForWeb.UI.Filters;

public class ManagerAuthorizeFilter : Attribute, IAuthorizationFilter
{
  public void OnAuthorization(AuthorizationFilterContext context)
  {
    var mvm = context.HttpContext.Session.Get<ManagerViewModel>("manager");
    if (mvm == null) context.Result = new RedirectResult("/admin/identity/login");
  }
}
